<template>
  <div class="div_box">
    <el-row :gutter="40" class="panel-group">
      <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
        <div class="card-panel" @click="routeToReport()">
          <div class="card-panel-icon-wrapper icon-card">
            <svg-icon icon-class="running" class-name="card-panel-icon" />
          </div>
          <div class="card-panel-description">
            <div class="card-panel-text">
              Running Tasks
            </div>
            <span class="card-panel-num">{{ taskInfo.runningTasks }}</span>
          </div>
        </div>
      </el-col>
      <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
        <div class="card-panel" @click="routeToReport()">
          <div class="card-panel-icon-wrapper icon-card">
            <svg-icon icon-class="waiting" class-name="card-panel-icon" />
          </div>
          <div class="card-panel-description">
            <div class="card-panel-text">
              Waiting Tasks
            </div>
            <span class="card-panel-num">{{ taskInfo.waitingTasks }}</span>
          </div>
        </div>
      </el-col>
      <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
        <div class="card-panel" @click="routeToReport()">
          <div class="card-panel-icon-wrapper icon-card">
            <svg-icon icon-class="finish" class-name="card-panel-icon" />
          </div>
          <div class="card-panel-description">
            <div class="card-panel-text">
              Finished Tasks
            </div>
            <span class="card-panel-num">{{ taskInfo.finishedTasks }}</span>
          </div>
        </div>
      </el-col>
      <el-col :xs="12" :sm="12" :lg="6" class="card-panel-col">
        <div class="card-panel" @click="routeToReport()">
          <div class="card-panel-icon-wrapper icon-card">
            <svg-icon icon-class="error" class-name="card-panel-icon" />
          </div>
          <div class="card-panel-description">
            <div class="card-panel-text">
              Error Tasks
            </div>
            <span class="card-panel-num">{{ taskInfo.errorTasks }}</span>
          </div>
        </div>
      </el-col>
    </el-row>
    <el-row style="background:#fff;padding:16px 16px 0;margin-bottom:32px;">
      <RunningTasks v-if="show === 0" />
      <WaitingTasks v-if="show === 1" />
      <FinishedTasks v-if="show === 2" />
      <ErrorTasks v-if="show === 3" />
    </el-row>
  </div>
</template>

<script scoped="scoped">
import { countByStatus } from '@/api/perf/report'
import RunningTasks from './index-running-tasks'
import WaitingTasks from './index-waiting-tasks'
import FinishedTasks from './index-finished-tasks'
import ErrorTasks from './index-error-tasks'
export default {
  components: { RunningTasks, WaitingTasks, FinishedTasks, ErrorTasks },
  data() {
    return {
      taskInfo: {},
      show: 0
    }
  },
  created() {
    this.countByStatus()
  },
  methods: {
    countByStatus() {
      countByStatus().then(respnose => {
        if (respnose && respnose.code === 200) {
          const { data } = respnose
          this.taskInfo = data
        } else {
          this.$message.error(respnose)
        }
      })
    },
    routeToReport() {
      // 这里不要删除缓存了
      // this.$store.dispatch('tagsView/delView', { name: 'PerfReport', path: '/perf/perf-report' })
      this.$nextTick(() => {
        this.$router.push({ name: 'PerfReport' })
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.panel-group {
  margin-top: 18px;

  .card-panel-col {
    margin-bottom: 32px;
  }

  .card-panel {
    height: 108px;
    cursor: pointer;
    font-size: 12px;
    position: relative;
    overflow: hidden;
    color: #666;
    background: #fff;
    box-shadow: 4px 4px 40px rgba(0, 0, 0, .05);
    border-color: rgba(0, 0, 0, .05);

    &:hover {
      .card-panel-icon-wrapper {
        color: #fff;
      }

      .icon-card {
        background: #eb670961;
      }
    }

    .icon-card {
      color: #FFFFFF;
    }

    .card-panel-icon-wrapper {
      float: left;
      margin: 14px 0 0 14px;
      padding: 16px;
      transition: all 0.38s ease-out;
      border-radius: 6px;
    }

    .card-panel-icon {
      float: left;
      font-size: 48px;
    }

    .card-panel-description {
      float: right;
      font-weight: bold;
      margin: 26px;
      margin-left: 0px;

      .card-panel-text {
        line-height: 18px;
        color: rgba(0, 0, 0, 0.45);
        font-size: 16px;
        margin-bottom: 12px;
      }

      .card-panel-num {
        font-size: 20px;
      }
    }
  }
}

@media (max-width:550px) {
  .card-panel-description {
    display: none;
  }

  .card-panel-icon-wrapper {
    float: none !important;
    width: 100%;
    height: 100%;
    margin: 0 !important;

    .svg-icon {
      display: block;
      margin: 14px auto !important;
      float: none !important;
    }
  }
}

.div_box {
  border: 1px solid #eee;
  padding-left: 15px;
  padding-right: 15px;
  padding-top: 15px;
  padding-bottom: 10px;
  margin-top: 10px;
  margin-bottom: 10px;
  width: 100%;
  height: 100%;
  overflow-y: auto;
  overflow-x: auto;
}
</style>
